﻿<?php
if(!empty($_POST['formAction'])){
	$email = empty($_POST['email']) ? '' : trim($_POST['email']);
	$resend = empty($_POST['resend']) ? 0 : 1;	// 是否重新发送邮件
	if(empty($email) || preg_match(Statics::$rgx['email'], $email) == false){
		ajax_msg('warning', '未输入邮箱地址或格式不正确', 'callback_email_bind');
	}

	if($resend == false){
		if($email == $__userinfo['email']){
			ajax_msg('warning', '新邮箱与原邮箱相同', 'callback_email_bind');
		}
		$r = $__oUser->update($__userid, array('email' => $email, 'email_verified' => 0));
	}

	if($resend || $r['result'] == 'succ'){
		// 确认地址
		$_str = serialize(array(
			'userid'	=> $__userid,
			'email'		=> $email,
		));
		$confirm_code	= base64_encode(php_authcode($_str, $operation = 'ENCODE', $key = '', $expiry = 86400 * 2));
		$confirm_url	= WEB_URL."index.php?frm=user&mdl=email&do=confirm&code={$confirm_code}";

		$oMail = new Mail($__f_sysvars['email_smtp_server'], 'smtp');
		$sr = $oMail->send('email_confirm', $email, $__userinfo['nickname'], array(
			'nickname'		=> $__userinfo['nickname'],
			'subject'		=> "{$__userinfo['nickname']},邮箱绑定确认",
			'altbody'		=> "请将地址复制到您的浏览器(例如IE)的地址栏访问：{$confirm_url}",
			'confirm_url'	=> $confirm_url,
		), $resend);
		if($sr == 'succ'){
			ajax_msg('succ', '', 'callback_email_bind', $r['data']['synjs']);
		}else{
			ajax_msg('warning', $sr, 'callback_email_bind');
		}
	}
	ajax_msg($r['result'], $r['rmsg'], 'callback_email_bind');
}

?>